/*
 * TcpListener.h
 *
 *  Created on: Jun 22, 2016
 *      Author: Lucifer
 */

#ifndef BFX_NET_ACCEPTOR_H_
#define BFX_NET_ACCEPTOR_H_

#include "./Socket.h"
#include "./SelectableChannel.h"
#include "./SelectionKey.h"

namespace BFX {

class TcpListener : public RCObject {
public:
	typedef void (*ListenerCallback)(TcpListener* listener);

	TcpListener(InetAddress* address);
	virtual ~TcpListener();

	bool start(Selector* sel, ListenerCallback callback);
	void stop();

	bool accept(Socket* rSocket);

private:
	static void eventCallback(SelectionKey* key);

	REF<SelectableChannel> _channel;
	bool _active;
	ListenerCallback _callback;
};

} /* namespace BFX */

#endif /* BFX_NET_ACCEPTOR_H_ */
